﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace luanvanFinal
{
    class clsProgress
    {
        int idProject;
        Nullable<DateTime> progress1 = null;
        int plan1;
        int actual1;
        Nullable<DateTime> progress2 = null;
        int plan2;
        int actual2;
        Nullable<DateTime> progress3 = null;
        int plan3;
        int actual3;
        Nullable<DateTime> progress4 = null;
        int plan4;
        int actual4;
        Nullable<DateTime> progress5 = null;
        int plan5;
        int actual5;
        Nullable<DateTime> progress6 = null;
        int plan6;
        int actual6;
        public int IdProject
        {
            get { return idProject; }
            set { idProject = value; }
        }
        public Nullable<DateTime> Progress1
        {
            get { return progress1; }
            set { progress1 = value; }
        }
        public int Plan1
        {
            get { return plan1; }
            set { plan1 = value; }
        }
        public int Actual1
        {
            get { return actual1; }
            set { actual1 = value; }
        }
        public Nullable<DateTime> Progress2
        {
            get { return progress2; }
            set { progress2 = value; }
        }
        public int Plan2
        {
            get { return plan2; }
            set { plan2 = value; }
        }
        public int Actual2
        {
            get { return actual2; }
            set { actual2 = value; }
        }
        public Nullable<DateTime> Progress3
        {
            get { return progress3; }
            set { progress3 = value; }
        }
        public int Plan3
        {
            get { return plan3; }
            set { plan3 = value; }
        }
        public int Actual3
        {
            get { return actual3; }
            set { actual3 = value; }
        }
        public Nullable<DateTime> Progress4
        {
            get { return progress4; }
            set { progress4 = value; }
        }
        public int Plan4
        {
            get { return plan4; }
            set { plan4 = value; }
        }
        public int Actual4
        {
            get { return actual4; }
            set { actual4 = value; }
        }
        public Nullable<DateTime> Progress5
        {
            get { return progress5; }
            set { progress5 = value; }
        }
        public int Plan5
        {
            get { return plan5; }
            set { plan5 = value; }
        }
        public int Actual5
        {
            get { return actual5; }
            set { actual5 = value; }
        }
        public Nullable<DateTime> Progress6
        {
            get { return progress6; }
            set { progress6 = value; }
        }
        public int Plan6
        {
            get { return plan6; }
            set { plan6 = value; }
        }
        public int Actual6
        {
            get { return actual6; }
            set { actual6 = value; }
        }
        public clsProgress()
        {
            idProject=0;
            progress1 = null;
            plan1=0;
            actual1=0;
            progress2 = null;
            plan2=0;
            actual2=0;
            progress3 = null;
            plan3=0;
            actual3=0;
            progress4 = null;
            plan4=0;
            actual4=0;
            progress5 = null;
            plan5=0;
            actual5=0;
            progress6 = null;
            plan6=0;
            actual6=0;
        }
        public void insertProgress()
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            try
            {
                SqlCommand sqlcmd = new SqlCommand("insertProgress", ketnoi.Connection);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.Parameters.Add("@idProject", SqlDbType.Int).Value = this.idProject;
                sqlcmd.Parameters.Add("@progress1", SqlDbType.DateTime).Value = this.progress1;
                sqlcmd.Parameters.Add("@plan1", SqlDbType.Int).Value = this.plan1;
                sqlcmd.Parameters.Add("@actual1", SqlDbType.Int).Value = this.actual1;
                sqlcmd.Parameters.Add("@progress2", SqlDbType.DateTime).Value = this.progress2;
                sqlcmd.Parameters.Add("@plan2", SqlDbType.Int).Value = this.plan2;
                sqlcmd.Parameters.Add("@actual2", SqlDbType.Int).Value = this.actual2;
                sqlcmd.Parameters.Add("@progress3", SqlDbType.DateTime).Value = this.progress3;
                sqlcmd.Parameters.Add("@plan3", SqlDbType.Int).Value = this.plan3;
                sqlcmd.Parameters.Add("@actual3", SqlDbType.Int).Value = this.actual3;
                sqlcmd.Parameters.Add("@progress4", SqlDbType.DateTime).Value = this.progress4;
                sqlcmd.Parameters.Add("@plan4", SqlDbType.Int).Value = this.plan4;
                sqlcmd.Parameters.Add("@actual4", SqlDbType.Int).Value = this.actual4;
                sqlcmd.Parameters.Add("@progress5", SqlDbType.DateTime).Value = this.progress5;
                sqlcmd.Parameters.Add("@plan5", SqlDbType.Int).Value = this.plan5;
                sqlcmd.Parameters.Add("@actual5", SqlDbType.Int).Value = this.actual5;
                sqlcmd.Parameters.Add("@progress6", SqlDbType.DateTime).Value = this.progress6;
                sqlcmd.Parameters.Add("@plan6", SqlDbType.Int).Value = this.plan6;
                sqlcmd.Parameters.Add("@actual6", SqlDbType.Int).Value = this.actual6;
                sqlcmd.ExecuteNonQuery();
            }
            catch 
            {
                //MessageBox.Show("Dữ liệu đã tồn tại hoặc không hợp lệ!!!" + ex.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ketnoi.closeConnection();
        }

        public void updateProgress()
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            try
            {
                SqlCommand sqlcmd = new SqlCommand("updateProgress", ketnoi.Connection);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.Parameters.Add("@idProject", SqlDbType.Int).Value = this.idProject;
                sqlcmd.Parameters.Add("@progress1", SqlDbType.DateTime).Value = this.progress1;
                sqlcmd.Parameters.Add("@plan1", SqlDbType.Int).Value = this.plan1;
                sqlcmd.Parameters.Add("@actual1", SqlDbType.Int).Value = this.actual1;
                sqlcmd.Parameters.Add("@progress2", SqlDbType.DateTime).Value = this.progress2;
                sqlcmd.Parameters.Add("@plan2", SqlDbType.Int).Value = this.plan2;
                sqlcmd.Parameters.Add("@actual2", SqlDbType.Int).Value = this.actual2;
                sqlcmd.Parameters.Add("@progress3", SqlDbType.DateTime).Value = this.progress3;
                sqlcmd.Parameters.Add("@plan3", SqlDbType.Int).Value = this.plan3;
                sqlcmd.Parameters.Add("@actual3", SqlDbType.Int).Value = this.actual3;
                sqlcmd.Parameters.Add("@progress4", SqlDbType.DateTime).Value = this.progress4;
                sqlcmd.Parameters.Add("@plan4", SqlDbType.Int).Value = this.plan4;
                sqlcmd.Parameters.Add("@actual4", SqlDbType.Int).Value = this.actual4;
                sqlcmd.Parameters.Add("@progress5", SqlDbType.DateTime).Value = this.progress5;
                sqlcmd.Parameters.Add("@plan5", SqlDbType.Int).Value = this.plan5;
                sqlcmd.Parameters.Add("@actual5", SqlDbType.Int).Value = this.actual5;
                sqlcmd.Parameters.Add("@progress6", SqlDbType.DateTime).Value = this.progress6;
                sqlcmd.Parameters.Add("@plan6", SqlDbType.Int).Value = this.plan6;
                sqlcmd.Parameters.Add("@actual6", SqlDbType.Int).Value = this.actual6;
                sqlcmd.ExecuteNonQuery();
            }
            catch 
            {
                //MessageBox.Show("Dữ liệu đã tồn tại hoặc không hợp lệ!!!" + ex.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ketnoi.closeConnection();
        }

        public void deleteProgress()
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            try
            {
                SqlCommand sqlcmd = new SqlCommand("deleteProgress", ketnoi.Connection);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.Parameters.Add("@idProject", SqlDbType.Int).Value = this.idProject;
                sqlcmd.ExecuteNonQuery();
                //MessageBox.Show("You have delete success !!!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch
            {
                MessageBox.Show("You have error while deleting progress!!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ketnoi.closeConnection();
        }

        public DataTable getDataProject(String strSQL)
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            SqlDataAdapter da = new SqlDataAdapter(strSQL, ketnoi.Connection);
            DataTable dt = new DataTable();
            da.Fill(dt);
            ketnoi.closeConnection();
            return dt;
        }

    }
}
